package io.noties.markwon.prism4j.languages;

import static java.util.regex.Pattern.CASE_INSENSITIVE;
import static java.util.regex.Pattern.compile;
import static io.noties.prism4j.Prism4j.grammar;
import static io.noties.prism4j.Prism4j.pattern;
import static io.noties.prism4j.Prism4j.token;

import org.jetbrains.annotations.NotNull;

import io.noties.prism4j.Prism4j;

@SuppressWarnings("unused")
public class Prism_lua {

  @NotNull
  public static Prism4j.Grammar create(@NotNull Prism4j prism4j) {
    return grammar("lua",
      token("comment", pattern(compile("^--(?:\\[(=*)\\[[\\s\\S]*?(?:\\]\\1\\]|$)|[^\\r\\n]*)"))),
      token("string", pattern(compile("^(?:\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S])*(?:\\\"|$)|\\'(?:[^\\'\\\\]|\\\\[\\s\\S])*(?:\\'|$))"))),
      token("operator", pattern(compile("(?:::|[:|'])\\b[a-z][\\w*+!?-]*\\b", CASE_INSENSITIVE))),
      token("keyword",
        pattern(
          compile("^(?:and|break|do|else|elseif|end|false|for|function|if|in|local|nil|not|or|repeat|return|then|true|until|while)\\b"),
                  true
        )
      ),
      token("boolean", pattern(compile("\\b(?:true|false|nil)\\b"))),
      token("number", pattern(compile("\\b[0-9A-Fa-f]+\\b"))),
      token("punctuation", pattern(compile("^[^\\w\\t\\n\\r \\xA0][^\\w\\n\\r \\xA0\\\"\\'\\-\\+=]*")))
    );
  }
}
